;(function ($,window,document,undefined){
	
	CP.Dashboard = function (){

		var _this = this;
		var html = '<div id="{0}"" class="{1}"></div>';

		this.$el = null;
		this.leftModule = null;
		this.rightModule = null;
		this.controlModule = null;

		//DASHBOARD SẼ QUẢN LÝ ORDER CỦA USER
		this.orderModule = null;

		this.init = function () {

			console.log('DASHBOARD INIT');

			html = html.format(MYLIB.constant.dashboard_id,MYLIB.constant.dashboard_class);
			
			this.$el = $(html);

			this.leftModule = new CP.LeftZone();

			this.leftModule.init();

			this.rightModule = new CP.RightZone();

			this.rightModule.init();

			this.controlModule = new CP.ControlModule();

			this.controlModule.init(this);

			this.orderModule = new CP.OrderModule(this);
			

			this.renderLayout();

			//BIND EVENT
			MYLIB.eventManager.subscribe(this,MYLIB.eventNames.event_checkout,'checkOutHandle');

		}

		this.getElement = function () {

			return this.$el;

		}

		this.renderLayout = function () {

			this.$el.append(this.leftModule.getElement());
			
			this.$el.append(this.rightModule.getElement());

			this.$el.append(this.controlModule.getElement());
		}


	};


	//CHECKOUT HANDLE
	CP.Dashboard.prototype.checkOutHandle = function (){
		console.log('DASHBOARD SẼ SỬ LÝ');
		/**
		 * 1. CHECK CANVAS INIT OR NOT?
		 */
		var instanceCanvas = this.rightModule.mainCanvas.getCanvas();
		if(!instanceCanvas){
			alert('Vui lòng chọn sản phẩm để design trước khi order!')
			return
		}
		/**
		 * 2. CHECK USER IS ANONYMOUS HAY ĐÃ ĐĂNG NHẬP RỒI
		 */
		if(this.checkStatusUser()){

			this.orderModule.init();
			this.orderModule.show();

		}
	}	

	/**
	 * CHECK USER LOGIN
	 */
	CP.Dashboard.prototype.checkStatusUser = function () {
		return true;
	}

})(jQuery,window,document)